package com.itheima.Exception;

import com.itheima.commons.Code;
import com.itheima.commons.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 * @Description:
 * @Version: V1.0
 */
@RestControllerAdvice
@Component
public class ProjectExceptionHandler {

    @ExceptionHandler({BusinessException.class})
    public Result doBusinessException(BusinessException ex){
        return ex.getResult();
    }

    /**
     * 不可预知异常,记录日志,发短信
     * @param ex
     * @return
     */
    @ExceptionHandler({Exception.class})
    public Result doException(Exception ex){
        return new Result(Code.ERROR,"您的网络有问题,请检查网络之后重新尝试");
    }
}
